package com.example.day4_fragment;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;

/***
 * 方式二：动态加载：很重要
 1。fragment布局
 2。创建fragment类
 3。使用java代码动态加载
 4.xml
 */
public class Main2Activity extends AppCompatActivity {
    private StaticFragment staticFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        staticFragment = new StaticFragment();

        //TODO 1：获得fragmentManager
        FragmentManager manager = getSupportFragmentManager();
        //TODO 2:开启事物
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        //TODO 3:add添加fragment
        //参数一 activity fragmeLayout容器id  参数二 fragment对象
        fragmentTransaction.add(R.id.frame,staticFragment);
        //TODO 4:提交事物
        fragmentTransaction.commit();



    }
}
